﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "GbmpParameterDisplayCreators.h"
#include "IGcmpBuiltInParameterDisplayCreator.h"
#include "IParameterDefinitionLibrary.h"
#include "GbmpBuiltInParameterDefinitionsNew.h"
#include "GcmpBuiltInParameterDefinitions.h"
#include "GbmpParameterLevelList.h"
#include "GbmpParameterBuildingStoreyList.h"
#include "IParameterValueInt.h"
#include "GbmpBuiltInParameterStaticVauleListItems.h"
#include "IParameterValueDisplayString.h"
#include "IParameterDisplayManager.h"
#include "ParameterProjectSpaceList.h"
#include "IParameterDisplay.h"
#include "ParameterType.h"
#include "GbmpParameterStandardValueList.h"
#include "GbmpParameterUCSList.h"
#include "DrawingBuiltInParameterDefinitions.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace gcmp;

namespace
{
    typedef std::vector<OwnerPtr<IParameterValueDisplayString>> ParameterValueDisplayStrings;
    
    OwnerPtr<IParameterDisplay> CreateStandardCodeParameterDisplay(const IDocument* pDoc, const gcmp::IParameterDefinition* pParameterDefinition)
    {
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pDoc, L"pDoc为空",L"GDMPLab",L"2024-03-30");
        DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParameterDefinition, L"pParameterDefinition为空",L"GDMPLab",L"2024-03-30");
        const std::wstring& code = pParameterDefinition->GetStandardCode();
        if (code == L"43311511")
        {
            //注册空间参数显示
            IParameterDefinitionLibrary* pParamDefLib = IParameterDefinitionLibrary::Get(pDoc);
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParamDefLib, L"pParamDefLib为空",L"GDMPLab",L"2024-03-30");
            int spaceConfigDefId = pParamDefLib->GetParameterDefinitionIdByStandardCode(L"43311511");
            // -1的情况：断网后获取不到编码数据
            if (-1 != spaceConfigDefId)
            {
                UniIdentity spaceConfigUid = IParameterDefinitionLibrary::Get(pDoc)->GetParameterDefinitionUidById(spaceConfigDefId);
                OwnerPtr<IParameterDisplay> opParameterDisplay = IParameterDisplay::CreateParameterDisplayDropdownList(spaceConfigUid, NEW_AS_OWNER_PTR(ParameterProjectSpaceList, spaceConfigUid));
                return opParameterDisplay;
            }
        }
        else if (code == L"43111117" || code == L"43311511" || code == L"43313511" || code == L"43511120" || code == L"43231717" || code == L"43511122")
        {
            if (pParameterDefinition->GetParameterTypeId() == PARAMETER_TYPE(ValueList))
            {
                OwnerPtr<IParameterDisplay> opDisplay = IParameterDisplay::CreateParameterDisplayDropdownList(pParameterDefinition->GetUid(), NEW_AS_OWNER_PTR(GbmpParameterStandardValueList, pParameterDefinition->GetUid()));
                return opDisplay;
            }
        }
        return nullptr;
    }

    void AddGbmpBuiltInParameterDisplayCreators()
    {
        //////////////////////////////////////////////////////////////////////////
        // Dynamic value list

        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(BuildingStoreyBuiltInParameter, GbmpParameterBuildingStoreyList);
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(GbmpViewWorkLevelBuiltInParameter, GbmpParameterLevelList);
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(TopAssociatedLevelBuiltInParameter, GbmpParameterLevelList);      // 顶部标高
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(BottomAssociatedLevelBuiltInParameter, GbmpParameterLevelList);   // 底部标高
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(ElementAssociatedLevelBuiltInParameter, GbmpParameterLevelList);  // 底部标高
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(AssociatedPlaneBuiltInParameter, GbmpParameterLevelList);         // 关联平面
        ADD_DYNAMIC_VALUE_LIST_PARAMETER_DISPLAY(ViewBindUserCoordSystemParameter, GbmpParameterUCSList);         // 用户坐标系
        //////////////////////////////////////////////////////////////////////////
        // Static value list

        // 结构类型
        {
            ParameterValueDisplayStrings StructureTypeValueList;
            StructureTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)StructureType::CastInPlaceConcrete), GBMP_TR(L"现浇混凝土")));
            //StructureTypeValueList.emplace_back(NEW_AS_OWNER_PTR(ParameterValueDisplayString, NEW_AS_OWNER_PTR(ParameterValueInt, (int)StructureType::Steel), GBMP_TR(L"钢结构")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(StructureTypeBuiltInParameter, StructureTypeValueList);
        }

        // 结构柱顶底截面样式
        {
            ParameterValueDisplayStrings ColumnTopBottomSectionTypeValueList;
            ColumnTopBottomSectionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(0), GBMP_TR(L"水平")));
            ColumnTopBottomSectionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(1), GBMP_TR(L"垂直于轴线")));
            ColumnTopBottomSectionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(2), GBMP_TR(L"竖直")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(ColumnTopSectionType, ColumnTopBottomSectionTypeValueList);
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(ColumnBottomSectionType, ColumnTopBottomSectionTypeValueList);
        }

        // 结构梁Z轴定位参数
        {
            ParameterValueDisplayStrings BeamZPositioningTypeValueList;
            BeamZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)BeamZPositioningType::Top), GBMP_TR(L"梁顶部")));
            BeamZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)BeamZPositioningType::Bottom), GBMP_TR(L"梁底部")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(BeamZPositioningTypeBuiltInParameter, BeamZPositioningTypeValueList);
        }

        // 楼板坡度定义方式
        {
            ParameterValueDisplayStrings FloorSlopeDefinitionTypeValueList;
            FloorSlopeDefinitionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(0), GBMP_TR(L"高度差")));
            FloorSlopeDefinitionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(1), GBMP_TR(L"角度")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(FloorSlopeDefinitionTypeBuiltInParameter, FloorSlopeDefinitionTypeValueList);
        }

        // 墙洞Z轴定位参数
        {
            ParameterValueDisplayStrings WallHoleZPositioningTypeValueList;
            WallHoleZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)WallHoleZPositioningType::Center), GBMP_TR(L"中心")));
            WallHoleZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)WallHoleZPositioningType::Bottom), GBMP_TR(L"底边")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(WallHoleZPositioningTypeBuiltInParameter, WallHoleZPositioningTypeValueList);
        }

        // 结构条形基础Z轴定位参数
        {
            ParameterValueDisplayStrings StripFoundationZPositioningTypeValueList;
            StripFoundationZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)StripFoundationZPositioningType::Top), GBMP_TR(L"基础顶部")));
            StripFoundationZPositioningTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)StripFoundationZPositioningType::Bottom), GBMP_TR(L"基础底部")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(StripFoundationZPositioningTypeBuiltInParameter, StripFoundationZPositioningTypeValueList);
        }

        // 结构筏板Z轴定位参数
        {
            ParameterValueDisplayStrings RaftFoundationZPositionTypeValueList;
            RaftFoundationZPositionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)RaftFoundationZPositioningType::Top), GBMP_TR(L"基础顶部")));
            RaftFoundationZPositionTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)RaftFoundationZPositioningType::Bottom), GBMP_TR(L"基础底部")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(RaftFoundationZPositioningTypeBuiltInParameter, RaftFoundationZPositionTypeValueList);
        }

        // 结构构件的混凝土强度等级
        {
            ParameterValueDisplayStrings StructureInstanceConcreteStrengthGradeList;
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C15), GBMP_TR(L"C15")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C20), GBMP_TR(L"C20")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C25), GBMP_TR(L"C25")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C30), GBMP_TR(L"C30")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C35), GBMP_TR(L"C35")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C40), GBMP_TR(L"C40")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C45), GBMP_TR(L"C45")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C50), GBMP_TR(L"C50")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C55), GBMP_TR(L"C55")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C60), GBMP_TR(L"C60")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C65), GBMP_TR(L"C65")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C70), GBMP_TR(L"C70")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C75), GBMP_TR(L"C75")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C80), GBMP_TR(L"C80")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C85), GBMP_TR(L"C85")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C90), GBMP_TR(L"C90")));
            StructureInstanceConcreteStrengthGradeList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)ConcreteStrengthGradeType::CSG_C95), GBMP_TR(L"C95")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(ConcreteStrengthGradeBuiltInParameter, StructureInstanceConcreteStrengthGradeList);
        }

        {
            ParameterValueDisplayStrings LevelTriangleHeaderTypeValueList;
            LevelTriangleHeaderTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)1), GBMP_TR(L"上标头")));
            LevelTriangleHeaderTypeValueList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create((int)2), GBMP_TR(L"下标头")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(LevelTriangleHeaderDirectionBuiltInParameter, LevelTriangleHeaderTypeValueList);
        }

        {
            ParameterValueDisplayStrings testModelWallList;
            testModelWallList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(0), GBMP_TR(L"空")));
            testModelWallList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(1), GBMP_TR(L"内部")));
            testModelWallList.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(2), GBMP_TR(L"外部")));
            ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(TestElementFlagBuiltInParameter, testModelWallList);
        }

        IParameterDisplayManager::SetParameterDisplayCreator(CreateStandardCodeParameterDisplay);
    }
    ONE_TIME_INITIALIZER(AddGbmpBuiltInParameterDisplayCreators);

    // 二维出图相关
    ParameterValueDisplayStrings GetDrawingViewportLockValueList()
    {
        ParameterValueDisplayStrings res;
        res.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(0), GBMP_TR(L"否")));
        res.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(1), GBMP_TR(L"是")));
        return res;
    }

    ParameterValueDisplayStrings GetDrawingViewportTypeDisplayTitleValueList()
    {
        ParameterValueDisplayStrings res;
        res.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(0), GBMP_TR(L"否")));
        res.emplace_back(IParameterValueDisplayString::CreateParameterValueDisplayString(IParameterValueInt::Create(1), GBMP_TR(L"是")));
        return res;
    }
    ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(DrawingViewPortLockBuiltInParameter, GetDrawingViewportLockValueList());
    ADD_STATIC_VALUE_LIST_PARAMETER_DISPLAY(DrawingViewportTypeDisplayTitleBuiltInParameter, GetDrawingViewportTypeDisplayTitleValueList());

}

